<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Category extends CI_Controller {
	function __construct() {
		parent::__construct();
	}
	function listcategory () {
		$this->load->model('category_model');
		$data['listCategory'] = $this->category_model->get_all_category();
		$this->load->view('index',$data);
	}
	function add_category() {
		if (isset($_REQUEST['submit'])) {
			$category_name = $this->input->post('sCateName', true);
			$category_root = $this->input->post('iCateRoot', true);
			$category_status = $this->input->post('iStatus', true);
			$this->load->model("category_model");
			$this->category_model->add_category($category_name, $category_root, $category_status);
			redirect("category/listcategory");
		}
		$this->load->model("category_model");
		$data['listCategory'] = $this->category_model->get_all_category();
		$this->load->view('index', $data);
	}
	function edit_category($id) {
		if (isset($_REQUEST["submit"])) {
			$this->load->model("category_model");
			$catename = $this->input->post('catename', true);
			$cateroot = $this->input->post('cateroot', true);
			$this->category_model->edit_category($id, $catename, $cateroot);
			redirect("category/listcategory");
		}
		$this->load->model("category_model");
		$data['catedetails'] = $this->category_model->get_category_by_id($id);
		$data['listcate'] = $this->category_model->get_root_category($id);
		$this->load->view('index', $data);
	}
	function del_category($id) {
		$this->load->model('category_model');
		$this->category_model->del_category($id);
		redirect("category/listcategory");
	}
}